package org.example.myleet.p434;

public class Solution {
    public int countSegments(String s) {
        int count = 0, segmentLen = 0;
        char c;
        for (int i = 0; i < s.length(); ++i) {
            c = s.charAt(i);
            if (c == ' ') {
                if (segmentLen > 0) {
                    ++count;
                }
                segmentLen = 0;
            } else {
                ++segmentLen;
            }
        }
        if (segmentLen > 0) {
            ++count;
        }
        return count;
    }
}
